//@ts-nocheck
import * as THREE from "three"

declare global {
  export namespace THREE {
    export class JMMesh<
      TGeometry extends THREE.BufferGeometry = THREE.BufferGeometry,
      TMaterial extends THREE.Material | THREE.Material[] = THREE.Material | THREE.Material[]
    > extends THREE.Mesh<TGeometry, TMaterial> {
      rootParent(): THREE.Object3D
    }
    export class JMSkinnedMesh<
      TGeometry extends THREE.BufferGeometry = THREE.BufferGeometry,
      TMaterial extends THREE.Material | THREE.Material[] = THREE.Material | THREE.Material[]
    > extends THREE.SkinnedMesh<TGeometry, TMaterial> {
      rootParent(): THREE.Object3D
    }
  }
}
export class JMMesh<
  TGeometry extends THREE.BufferGeometry = THREE.BufferGeometry,
  TMaterial extends THREE.Material | THREE.Material[] = THREE.Material | THREE.Material[]
> extends THREE.Mesh<TGeometry, TMaterial> {
  constructor(b, t) {
    super(b, t)
  }
  rootParent() {
    var parent = this.parent
    if (!parent) return this
    while (parent.parent) {
      if (parent.parent instanceof THREE.Scene) {
        break
      }
      parent = parent.parent
    }

    return parent
  }
}
//@ts-ignore
THREE.JMMesh = JMMesh
export class JMSkinnedMesh<
  TGeometry extends THREE.BufferGeometry = THREE.BufferGeometry,
  TMaterial extends THREE.Material | THREE.Material[] = THREE.Material | THREE.Material[]
> extends THREE.SkinnedMesh<TGeometry, TMaterial> {
  constructor(b, t) {
    super(b, t)
  }
  rootParent() {
    var parent = this.parent
    if (!parent) return this
    while (parent.parent) {
      if (parent.parent instanceof THREE.Scene) {
        break
      }
      parent = parent.parent
    }

    return parent
  }
}
//@ts-ignore
THREE.JMSkinnedMesh = JMSkinnedMesh
